/************************************************************
 * Project Name         [Thinking_In_Java]
 * File Name            [GroupLeader.java]
 * Creation Date        [24-Jul-2014]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ************************************************************/
package pkg_principles.ocp.example02;

import java.text.NumberFormat;
import java.util.ArrayList;

import pkg_principles.ocp.example01.IBook;
import pkg_principles.ocp.example01.NovelBook;

/**
 * 模拟书店
 * 
 * @author 不落的太阳(Sean Yang)
 * @version 1.0
 * @since JDK 6
 * 
 */
public class NewBookStore {

	private final static ArrayList<IBook> bookList = new ArrayList<IBook>();

	// 静态模块初始化, 项目中一般是从持久层初始化产生
	static {
		bookList.add(new NovelBook("天龙八部", 3200, "金庸"));
		bookList.add(new NovelBook("巴黎圣母院", 5600, "雨果"));
		bookList.add(new NovelBook("悲惨世界", 3500, "雨果"));
		bookList.add(new NovelBook("金瓶梅", 4300, "兰陵笑笑生"));
		// 增加计算机书籍
		bookList.add(new ComputerBook("Think in Java", 4300, "Bruce Eckel",
				"编程语言"));
	}

	/**
	 * 模拟书店买书
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		NumberFormat formatter = NumberFormat.getCurrencyInstance();
		formatter.setMaximumFractionDigits(2);
		System.out.println("------------------书店买出去的书籍记录如下:------------------");
		for (IBook book : bookList) {
			System.out.println("书籍名称: " + book.getName() + "\t书籍作者: "
					+ book.getAuthor() + "\t书籍价格: "
					+ formatter.format(book.getPrice() / 100.0) + "元");
		}
	}

}
